package utils;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;

import param.pub.Publicrequest;
import param.pub.Publicresponse;
import utils.jaxb.XmlUtil;

public class PublicInfoUtil {
	public static Publicresponse newPublicResponse(){
		Publicresponse res=new Publicresponse();
		res.setResultcode("");
		res.setResultmsg("");
		res.setReturntime((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
		res.setSignmsg("");
		res.setVersion("v1.0");
		return res;
	}
	public static Publicrequest newPublicRequest(){
		Publicrequest req=new Publicrequest();
		req.setAskorgcode("");
		req.setAskorgname("");
		req.setAsktime((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
		req.setSignmsg("");
		req.setTargetorgcode("");
		req.setVersion("v1.0");
		return req;
	}
	public static String toXml(Object obj){
		try {
			return XmlUtil.toXml(obj);
		} catch (Exception e) {
			String rootEleName = null;
			XmlRootElement annoclass = obj.getClass().getAnnotation(XmlRootElement.class);
			if(annoclass!=null){
				rootEleName = annoclass.name();
			}
			if(rootEleName==null){
				rootEleName = obj.getClass().getName();
			}
			return " <"+rootEleName+"><publicresponse><Resultcode>-1</Resultcode><Resultmsg>对象转换成XML异常</Resultmsg><Returntime>"+new Date()+"</Returntime><Version>1.0</Version><Signmsg>163f79d4785486d2a9520cf6700a0818</Signmsg></publicresponse></"+rootEleName+">";
//			return " <"+rootEleName+"><PublicInfo><DT_REQUEST_TIME>"+new Date()+"</DT_REQUEST_TIME><VC_BUSINESS_ID>testBN001</VC_BUSINESS_ID><VC_RE_CODE>201</VC_RE_CODE><VC_RE_TX>对象转换成XML异常</VC_RE_TX><VC_SIGN>163f79d4785486d2a9520cf6700a0818</VC_SIGN><VC_STATION_ID>GZMH01</VC_STATION_ID><VC_TERMINAL_NO></VC_TERMINAL_NO><VC_USER_ID></VC_USER_ID><VC_VERSION>版本01</VC_VERSION><sTmp1></sTmp1><sTmp2></sTmp2></PublicInfo></"+rootEleName+">";
		}
	}
}
